package com.mt.roll.wms.controller;

import com.alibaba.fastjson.JSON;
import com.mt.roll.core.annotation.OperationLog;
import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.dal.entity.CarTaskExecutionInfo;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.CarTaskExecutionInfoQueryParam;
import com.mt.roll.wms.service.CarTaskExecutionInfoService;
import com.mt.roll.wms.vo.CarTaskExecutionInfoVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * @auther why
 * @date 2021/9/27 15:56
 */
@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "car/task/execution/info")
@Slf4j
@Api(value = "当前任务列表", tags = "当前任务列表", hidden = false)
public class CarTaskExecutionInfoController extends BaseController {

    @Autowired
    private CarTaskExecutionInfoService carTaskExecutionInfoService;


    @PostMapping(value = "page")
    @ApiOperation(value = "分页当前任务列表")
    @OperationLog()
    private R<PageVo<CarTaskExecutionInfoVo>> page(@Validated({PageGroup.class, Default.class}) @RequestBody CarTaskExecutionInfoQueryParam carTaskExecutionInfoQueryParam) {
        return carTaskExecutionInfoService.page(carTaskExecutionInfoQueryParam);
    }

    @PostMapping(value = "get")
    @ApiOperation(value = "获取任务详情")
    private R<CarTaskExecutionInfoVo> get(@Validated @RequestBody IdParam idParam) {
        return carTaskExecutionInfoService.get(idParam);
    }

    @PostMapping(value = "mesTask")
    @ApiOperation(value = "接收mes的任务")
    private R<IdVo> mesTask(@RequestBody String param) {
        log.info("接收到的param数据："+ JSON.toJSONString(param));
        CarTaskExecutionInfo carTaskExecutionInfo = JSON.parseObject(JSON.toJSONString(param), CarTaskExecutionInfo.class);
        return carTaskExecutionInfoService.mesTask(carTaskExecutionInfo);
    }

}
